﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<QuizAppMvc2.Models.AvaliacaoModels>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Index
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2>
        Prova</h2>
    <% using (Html.BeginForm("Finish", "Setup", "Finish"))
       { %>
    <% Random rnd = new Random(); %>
    <p>
        <% for (int i = 0; i < Model.questoes.Count; i++)
           {
               int? novoGabarito = null;
        %>
        <%= i +1%>
        )
        <% if (Model.questoes[i].Questao.TipoQuestao == 1)
           {%>
           <h4>
        <%= (Model.questoes[i].Questao as QuizAppMvc2.QuestaoSimple).Texto%>
        </h4>
        <%--        <%=  Html.HiddenFor(m => m.questoes[i].idquestao)%>
        <%=  Html.RadioButtonFor(m => m.questoes[i].resposta, 1)%>certo<br />
        <%=  Html.RadioButtonFor(m => m.questoes[i].resposta, 2)%>errado<br />--%>
        <%=  Html.HiddenFor(m => m.questoes[i].idQuestao)%><br />
        <%=  Html.RadioButtonFor(m => m.questoes[i].Resultado, 1)%>certo<br />
        <%=  Html.RadioButtonFor(m => m.questoes[i].Resultado, 2)%>errado<br />
        <% }
           else if (Model.questoes[i].Questao.TipoQuestao == 2)
           {
               QuizAppMvc2.QuestaoMultipla qm = (Model.questoes[i].Questao as QuizAppMvc2.QuestaoMultipla);
        %>
        <h4>
        <%: qm.Texto%><br>
        </h4>
        <%: Html.HiddenFor(m => m.questoes[i].idQuestao) %>
        <% int count = qm.QuestaoAlternativas.Count;
           var sequence = Enumerable.Range(1, count).OrderBy(n => rnd.Next());
           List<int> vet = new List<int>();
           vet = sequence.ToList();



           for (int ii = 0; ii < count; ii++)
           {
               if (vet[ii] == qm.Gabarito)
               {
                   novoGabarito = ii + 1;
               }
               QuizAppMvc2.QuestaoAlternativa alternativa;
               alternativa = qm.QuestaoAlternativas.ElementAt(vet[ii] - 1);
               %>

               <%=  Html.RadioButtonFor(m => m.questoes[i].Resultado, alternativa.Alternativa )%>
                <%: alternativa.Texto %> <br />
                
               <%
               
           }
              
        %>
        <%} %>
        <br />
        <br />
        <% } %>
        <input type="submit" value="Finish" />
        <% } %>
    </p>
</asp:Content>
